home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / CellHints.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  7.7 KB  |  276 lines

  1. /*
  2.  * CellHints.java   1.0   12 Jan 1997
  3.  *
  4.  * Copyright (c) 1996 Krumel & Associates, Inc.  All Rights Reserved.
  5.  *
  6.  * This software is provided as is.  Krumel & Associates shall not be liable
  7.  * for any damages suffered by licensee as a result of using, modifying or
  8.  * distributing this software or its derivatives.
  9.  */
  10.  
  11. package symantec.itools.db.awt;
  12.  
  13. import java.awt.*;
  14.  
  15. public class CellHints {
  16.     Rectangle   bounds = new Rectangle();
  17.     int         align;
  18.     int         valign = Grid.TOP;
  19.     boolean     editable = true;
  20.     boolean     visible = true;
  21.     Font        font = stdFont;
  22.     Color       fg = Color.black;
  23.     Color       bg = Color.white;
  24.     Color       hfg = Color.white;
  25.     Color       hbg = Color.blue;
  26.     boolean     highlighted = false;
  27.     boolean     lineTop = true,
  28.                 lineBottom = true,
  29.                 lineLeft = true,
  30.                 lineRight = true;
  31.     int         lineTopStyle = Grid.THIN_LINE,
  32.                 lineBottomStyle = Grid.THIN_LINE,
  33.                 lineLeftStyle = Grid.THIN_LINE,
  34.                 lineRightStyle = Grid.THIN_LINE;
  35.     Color       lineTopColor = Color.gray,
  36.                 lineBottomColor = Color.gray,
  37.                 lineLeftColor = Color.gray,
  38.                 lineRightColor = Color.gray;
  39.     int         bits;
  40.  
  41.     public static final int ALIGN_BIT = 0;
  42.     public static final int VALIGN_BIT = 1;
  43.     public static final int EDITABLE_BIT = 2;
  44.     public static final int VISIBLE_BIT = 3;
  45.     public static final int FONT_BIT = 4;
  46.     public static final int FG_BIT = 5;
  47.     public static final int BG_BIT = 6;
  48.     public static final int HFG_BIT = 7;
  49.     public static final int HBG_BIT = 8;
  50.  
  51.     public static Font stdFont = new Font("Dialog", Font.PLAIN, 12);
  52.     Grid   view;
  53.     TableCell   cell;
  54.  
  55.     public CellHints(Grid v) {
  56.         view = v;
  57.     }
  58.  
  59.     public void set(int bit) {
  60.         bits |= (1<<bit);
  61.     }
  62.  
  63.     public void clear(int bit) {
  64.         bits &= ~(1L << bit);
  65.     }
  66.  
  67.     public boolean get(int bit) {
  68.         return ((bits >> bit) & 1) != 0;
  69.     }
  70.  
  71.     public void setForeground(Graphics g) {
  72.         if (highlighted) {
  73.             g.setColor(hfg);
  74.         } else {
  75.             g.setColor(fg);
  76.         }
  77.     }
  78.  
  79.     public void setBackground(Graphics g) {
  80.         if (highlighted) {
  81.             g.setColor(hbg);
  82.         } else {
  83.             g.setColor(bg);
  84.         }
  85.     }
  86.  
  87.     public void setHints(TableCell c) {
  88.         cell = c;
  89.  
  90.         if (cell.type() == TableCell.CORNER_CELL) {
  91.             setCornerCellHints(c);
  92.             return;
  93.         } else if (cell.type() == TableCell.ROW_HEADING) {
  94.             //Is this ever the case
  95.         } else if (cell.type() == TableCell.COL_HEADING) {
  96. //Need to implement this
  97.         }
  98.  
  99.         bounds = view.getCellBounds(c, bounds);
  100.         align = view.getCellAlignment(c);
  101.         fg = view.getCellFG(c);
  102.         bg = view.getCellBG(c);
  103.         editable = view.getCellEditable(c);
  104.         highlighted = view.getCellHighlighted(c);
  105.         font = view.getCellFont(c);
  106.     }
  107.  
  108.     void setCornerCellHints(TableCell c) {
  109.         CellHints rowHints = view.rowHeadingHints;
  110.  
  111.         bounds = view.getCellBounds(c, bounds);
  112.         align = rowHints.align;
  113.         fg = rowHints.fg;
  114.         bg = rowHints.bg;
  115.         editable = rowHints.editable;
  116.         highlighted = view.isViewSelected();
  117.         font = rowHints.font;
  118.     }
  119.  
  120.     public void drawBoundary(Graphics g) {
  121.         Rectangle r = bounds;
  122.         if (lineTop) {
  123.             g.setColor(lineTopColor);
  124.             g.drawLine(r.x, r.y, r.x+r.width-1, r.y);
  125.         }
  126.         if (lineBottom) {
  127.             g.setColor(lineBottomColor);
  128.             g.drawLine(r.x, r.y+r.height-1, r.x+r.width-1, r.y+r.height-1);
  129.         }
  130.         if (lineLeft) {
  131.             g.setColor(lineLeftColor);
  132.             g.drawLine(r.x, r.y, r.x, r.y+r.height-1);
  133.         }
  134.         if (lineRight) {
  135.             g.setColor(lineRightColor);
  136.             g.drawLine(r.x+r.width-1, r.y, r.x+r.width-1, r.y+r.height-1);
  137.         }
  138.     }
  139.  
  140.     public boolean isVisible() { return visible; }
  141.  
  142.     public boolean cascadeIsVisible(CellHints c1, CellHints c2) {
  143.         if (c2 != null && c2.get(VISIBLE_BIT)) {
  144.             return c2.visible;
  145.         } else if (c1 != null && c1.get(VISIBLE_BIT)) {
  146.             return c1.visible;
  147.         }
  148.  
  149.         return visible;
  150.     }
  151.  
  152.     public Rectangle bounds() { return bounds; }
  153.  
  154.     public int alignment() { return align; }
  155.  
  156.     public int cascadeAlignment(CellHints c1, CellHints c2) {
  157.         if (c2 != null && c2.get(ALIGN_BIT)) {
  158.             return c2.align;
  159.         } else if (c1 != null && c1.get(ALIGN_BIT)) {
  160.             return c1.align;
  161.         }
  162.  
  163.         return align;
  164.     }
  165.  
  166.     public boolean editable() { return editable; }
  167.  
  168.     public boolean cascadeEditable(CellHints c1, CellHints c2) {
  169.         if (c2 != null && c2.get(EDITABLE_BIT)) {
  170.             return c2.editable;
  171.         } else if (c1 != null && c1.get(EDITABLE_BIT)) {
  172.             return c1.editable;
  173.         }
  174.  
  175.         return editable;
  176.     }
  177.  
  178.     public int vAlignment() { return valign; }
  179.  
  180.     public int cascadeVAlignment(CellHints c1, CellHints c2) {
  181.         if (c2 != null && c2.get(VALIGN_BIT)) {
  182.             return c2.valign;
  183.         } else if (c1 != null && c1.get(VALIGN_BIT)) {
  184.             return c1.valign;
  185.         }
  186.  
  187.         return valign;
  188.     }
  189.  
  190.     public Font font() { return font; }
  191.  
  192.     public Font cascadeFont(CellHints c1, CellHints c2) {
  193.         if (c2 != null && c2.get(FONT_BIT)) {
  194.             return c2.font;
  195.         } else if (c1 != null && c1.get(FONT_BIT)) {
  196.             return c1.font;
  197.         }
  198.  
  199.         return font;
  200.     }
  201.  
  202.     public Color foreground() { return fg; }
  203.  
  204.     public Color cascadeForeground(CellHints c1, CellHints c2) {
  205.         if (c2 != null && c2.get(FG_BIT)) {
  206.             return c2.fg;
  207.         } else if (c1 != null && c1.get(FG_BIT)) {
  208.             return c1.fg;
  209.         }
  210.  
  211.         return fg;
  212.     }
  213.  
  214.     public Color background() { return bg; }
  215.  
  216.     public Color cascadeBackground(CellHints c1, CellHints c2) {
  217.         if (c2 != null && c2.get(BG_BIT)) {
  218.             return c2.bg;
  219.         } else if (c1 != null && c1.get(BG_BIT)) {
  220.             return c1.bg;
  221.         }
  222.  
  223.         return bg;
  224.     }
  225.  
  226.     public boolean highlighted() { return highlighted; }
  227.  
  228.     public Color hlForeground() { return hfg; }
  229.  
  230.     public Color cascadeHlForeground(CellHints c1, CellHints c2) {
  231.         if (c2 != null && c2.get(HFG_BIT)) {
  232.             return c2.hfg;
  233.         } else if (c1 != null && c1.get(HFG_BIT)) {
  234.             return c1.hfg;
  235.         }
  236.  
  237.         return hfg;
  238.     }
  239.  
  240.     public Color hlBackground() { return hbg; }
  241.  
  242.     public Color cascadeHlBackground(CellHints c1, CellHints c2) {
  243.         if (c2 != null && c2.get(HBG_BIT)) {
  244.             return c2.hbg;
  245.         } else if (c1 != null && c1.get(HBG_BIT)) {
  246.             return c1.hbg;
  247.         }
  248.  
  249.         return hbg;
  250.     }
  251.  
  252.     public boolean lineTop() { return lineTop; }
  253.  
  254.     public boolean lineBottom() { return lineBottom; }
  255.  
  256.     public boolean lineLeft() { return lineLeft; }
  257.  
  258.     public boolean lineRight() { return lineRight; }
  259.  
  260.     public Color lineTopColor() { return lineTopColor; }
  261.  
  262.     public Color lineBottomColor() { return lineBottomColor; }
  263.  
  264.     public Color lineLeftColor() { return lineLeftColor; }
  265.  
  266.     public Color lineRightColor() { return lineRightColor; }
  267.  
  268.     public int lineTopStyle() { return lineTopStyle; }
  269.  
  270.     public int lineBottomStyle() { return lineBottomStyle; }
  271.  
  272.     public int lineLeftStyle() { return lineLeftStyle; }
  273.  
  274.     public int lineRightStyle() { return lineRightStyle; }
  275. }
  276.